<?php

require_once BaseUtil::getModulePath("base") . '/forms/BaseForm.php';
require_once BaseUtil::getModulePath("base") . '/validate/Unique.php';

class MarketingMappingForm extends BaseForm {
	public function __construct($edit = false,$mappingId = null) {
	   parent::__construct();
        if($edit){
            $this->setAction(HttpUtil::getUrl("marketingmapping","subedit"));
        }else{
            $this->setAction(HttpUtil::getUrl("marketingmapping","subadd"));
        }
		//id
		if($edit){
			$id = new Zend_Form_Element_Hidden('id');
			$this->addElement($id);
		}
		
		//unique validate
	    $validaUnique = new MyValid_Unique();
        $validaUnique->setTableName('marketing_mappings');
        $validaUnique->setFieldName('mapping_key');
        if (!empty($mappingId)){
            $validaUnique->setId($mappingId);
        }
		
		//mapping mapping_key
		$key = new Zend_Form_Element_Text('mapping_key');
        $key->setLabel($this->translate->_('mapping_key'));
        $key->addFilter("StringTrim");
        $key->addValidator($validaUnique);       
        $key->setRequired(true);
		
		//mapping mapping_value
		$value = new Zend_Form_Element_Text('mapping_value');
        $value->setLabel($this->translate->_('mapping_value'));
        $value->addFilter("StringTrim");       
        $value->setRequired(true);
		
		$this->addElements(array($key,$value));
		$this->setElementDecorators(array ('ViewHelper',array(array('div' =>'HtmlTag'),array('tag' =>'div',"class" => "form_element"))));
	}
}